<template>
    <div class="big_box">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>财务管理</el-breadcrumb-item>
            <el-breadcrumb-item>报销管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-divider></el-divider>


        <el-form class="demo-form-inline row-bg" :model="finance" ref="queryform_FinanceReimbursement">
            <el-row :gutter="5">
                <el-col :span="3" style="padding-right:0px;">
                    <el-form-item class="elformitem" prop="ReimNumber">
                        <el-input v-model="finance.ReimNumber" placeholder="请输入报销单编号"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="3">
                    <el-form-item class="elformitem" prop="Project">
                        <el-select style="width:100%" v-model.number="finance.Project"  filterable clearable required placeholder="请选择项目">
                            <el-option label="请选择项目" :value="0"></el-option>
                            <el-option v-for="(v,k) in AllProject" :value="v.Id" :data-userid="v.Id" :label="v.ProjectName" v-text="v.ProjectName" />
                        </el-select>
                    </el-form-item>
                </el-col>

                <el-col :span="3">
                    <el-form-item class="elformitem" prop="Borrower">
                        <el-select style="width:100%" v-model.number="finance.Borrower"  filterable clearable   required placeholder="请选择申请人">
                            <el-option label="请选择请款人" :value="0"></el-option>
                            <el-option v-for="(v,k) in AllUsers" :value="v.Id" :data-userid="v.Id" :label="v.UserName" v-text="v.UserName" />
                        </el-select>
                    </el-form-item>
                </el-col>
<el-col :span="3">
                    <el-date-picker
                                    style="width:100%"
                                    v-model="form.Start"
                                    type="date"
                                    placeholder="开始时间">
                    </el-date-picker>
                </el-col>
                <el-col :span="3">
                    <el-date-picker
                                      style="width:100%"
                                    v-model="form.End"
                                    type="date"
                                    placeholder="结束时间">
                    </el-date-picker>
                </el-col>
                <el-col :span="1">
                    <el-button icon="el-icon-search" style="width:100%" type="success"  @click="GetFinanceReimbursementDetail()"></el-button>
                </el-col>
                <el-col :span="1">
                    <el-button icon="el-icon-refresh-right" style="width:100%" type="success"  @click="GetFinanceReimbursementDetail_Refresh()"></el-button>
                </el-col>
            </el-row>

            <el-row style="padding:10px">
                <el-col>
                    <el-button-group>
                        <el-button class="buttongroup" type="danger" icon="el-icon-delete" @click="DelArray">批量删除</el-button>
                        <el-button class="buttongroup" type="success" icon="el-icon-circle-plus-outline" @click="ShowAddFinanceReimbursement">添加</el-button>
                    </el-button-group>
                </el-col>
            </el-row>

            <el-row style="padding:10px 0px">
                <el-col :span="24">
                    <el-table :data="tableData"
                              border
                              @selection-change="SelectionChange_event">
                        <el-table-column header-align="center" type="selection" width="50" align="center"></el-table-column>
                        <el-table-column header-align="center" fixed type="index" label="序号" align="center" :index="_indexMethod"></el-table-column>
                        <el-table-column header-align="center" align="center" prop="ReimNumber" label="单据编号" width="130px"></el-table-column>
                        <el-table-column prop="Type" header-align="center" align="center" label="报销类别">
                        </el-table-column>
                        <el-table-column header-align="center" align="center" prop="Borrower" label="报销人">
                            <template slot-scope="scope">
                                <label>{{_UserById(scope.row.Borrower)}}</label>
                            </template>
                        </el-table-column>
                        <el-table-column header-align="center" align="center" prop="Money" label="报销金额"></el-table-column>
                        <el-table-column header-align="center" align="center" prop="BorrowTime" label="报销时间" width="190px">
                            <template slot-scope="scope">
                                <label>{{(scope.row.BorrowTime)}}</label>
                                <!--formatDateTime(scope.row..BorrowTime);-->
                            </template>
                        </el-table-column>
                        <el-table-column prop="Content" header-align="center" align="center" label="报销内容">
                        </el-table-column>
                         <el-table-column prop="Abstract" header-align="center" align="center" label="内容摘要">
                        </el-table-column>
                        <el-table-column prop="Project" header-align="center" align="center" label="项目" width="190px" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                {{_GetProjectById(scope.row.Project)}}
                                <!--formatDateTime(scope.row..BorrowTime);-->
                            </template>
                        </el-table-column>
                        <el-table-column prop="Remark" header-align="center" align="center" label="备注" width="210px" :show-overflow-tooltip="true"></el-table-column>
                        <el-table-column prop="address" header-align="center" align="center" label="操作" fixed="right" width="200px">
                            <template slot-scope="scope">
                                <el-button type="info" class="BtnSize" size="mini" plain @click="edit(scope.row)">编辑</el-button>
                                <el-button type="danger" class="BtnSize" size="mini" plain @click="del(scope.row)"> 删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>

                <el-col :span="24">
                    <div class="block" style="text-align:right">
                        <el-pagination @size-change="GetFinanceReimbursementDetail"
                                       @current-change="GetFinanceReimbursementDetail"
                                       :current-page.sync="pagination.currentPage"
                                       :page-sizes="pagination.pagesizes"
                                       :page-size.sync="pagination.pagesize"
                                       layout="total, sizes, prev, pager, next, jumper"
                                       :total.sync="pagination.total">
                        </el-pagination>
                    </div>
                </el-col>
            </el-row>
        </el-form>

        <el-dialog :visible.sync="AddFinanceReimbursementShow" width="60%"  top="10px" title="添加报销详情">
            <AddFinanceReimbursement :AllCategory="AllCategory"
                                     :GetPayArray="GetPayArray"
                                     :AllUsers="AllUsers"
                                     :AllProject="AllProject"
                                     :AllDepartment="AllDepartment">
            </AddFinanceReimbursement>
        </el-dialog>

        <el-dialog :visible.sync="UpFinanceReimbursementShow" width="60%"  top="10px" title="修改报销详情">
            <UpFinanceReimbursement
                                    :FinanceLoanDB="FinanceLoanDB"
                                    :AllCategory="AllCategory"
                                    :GetPayArray="GetPayArray"
                                    :AllUsers="AllUsers"
                                    :AllProject="AllProject"
                                    :AllDepartment="AllDepartment"
                                    >

            </UpFinanceReimbursement>
        </el-dialog>

        <el-dialog :visible.sync="FinanceReimbursementOrderShow" v-if="FinanceReimbursementOrderShow" @close="GetFinanceReimbursementDetail"    :fullscreen="true" title="报销单">
            <FinanceReimbursementOrder
                                       :Orderdata="FinanceLoanDB"
                                       :AllCategory="AllCategory"
                                       :GetPayArray="GetPayArray"
                                       :AllUsers="AllUsers"
                                       :AllProject="AllProject"
                                       :AllDepartment="AllDepartment"
                                       :detailed="detailed"
                                       :TableTypeNumber="FinanceLoanDB.FinanceType"
                                       :AllCustomer="AllCustomer">
            </FinanceReimbursementOrder>
        </el-dialog>



        <el-dialog :visible.sync="ViewFinanceAndRecordShow" title="报销单" :fullscreen="true">
            <ViewFinanceAndRecord :AllProject="AllProject"
                                  :AllDepartment="AllDepartment"
                                  :AllUsers="AllUsers"
                                  :AllCustomer="AllCustomer"
                                  :AllCategory="AllCategory"
                                  :ViewFinanceAndRecorDB="ViewFinanceAndRecorDB">
            </ViewFinanceAndRecord>
        </el-dialog>



    </div>
</template>
<script>
    import * as publicjs from "/public/Scriput/Public"
    import AddFinanceReimbursement from "./AddFinanceReimbursement";
    import UpFinanceReimbursement from "./UpFinanceReimbursement";
    import ViewFinanceAndRecord from "./ViewFinanceAndRecord";
    //申请单
    import FinanceReimbursementOrder from "../../Report/FinanceReimbursementOrder";
    import { Loading } from "element-ui";

    export default {
        name: "FinanceReimbursement",
        components: {
            AddFinanceReimbursement: AddFinanceReimbursement,
            UpFinanceReimbursement: UpFinanceReimbursement,
            FinanceReimbursementOrder: FinanceReimbursementOrder,
            ViewFinanceAndRecord: ViewFinanceAndRecord,
        },
        data() {
            return {
                //页面展示开始
                AddFinanceReimbursementShow: false,
                UpFinanceReimbursementShow: false,
                FinanceReimbursementOrderShow: false,
                ViewFinanceAndRecordShow: false,
                //页面展示结束

                //数据查看开始
                form: {
                },
                date: {
                    Start: "",
                    End: "",
                },
                finance: {
                    Borrower: 0,
                    Project: 0,
                },
                //数据查看结束
                tableData: [],
                SelectMore_lis: [],
                //分页数据绑定
                pagination: {
                    currentPage: 1,
                    pagesizes: [10, 20, 30, 40, 50],
                    pagesize: 10,
                    total: 0
                },
                //数据获取
                AllProject: [],
                AllUsers: [],
                GetPayArray: [],
                AllCategory: [],
                //数据获取结束

                //数据修改开始
                FinanceLoanDB: {},
                //数据修改结束
                detailed: [],


                //数据传递 报销表展示开始
                ViewFinanceAndRecorDB: {},
                //数据传递 报销表展示结束

            }
        },
        created() {
            this.AllUsers = publicjs.GetCompanyAllUsers(this.$http);
            this.AllProject = publicjs.GetAllProject(this.$http);
            this.GetPayArray = publicjs.GetPayArray(this.$http);
            this.GetFinanceReimbursementDetail();
            this.GetAllFinanceCategorytoarray();
        },
        methods: {
            //获取相关信息
            GetAllFinanceCategorytoarray() {
                this.$http.get("/PublicMethodApi/GetAllFinanceCategory").then(x => {
                    for (var i = 0; i < x.data.length; i++) {
                        this.AllCategory.push(x.data[i])
                    }
                }).catch(() => {
                    this.$message.error('服务器异常,请联系管理员!')
                })
            },
            //序号
            _indexMethod(index) {
                return ((this.pagination.currentPage - 1) * this.pagination.pagesize) + index + 1
            },

            //表格数据选择事件
            SelectionChange_event(value) {
                this.SelectMore_lis = value
            },
            //删除
            del(obj) {
                this.SelectMore_lis = [];
                this.SelectMore_lis.push(obj);
                this.DelArray();
            },
            //批量删除
            DelArray() {
                this.$confirm('你确定要删除吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消'
                }).then(() => {
                    let arrDel = []
                    if (this.SelectMore_lis.length > 0) {
                        this.SelectMore_lis.forEach(item => {
                            arrDel.push(item.Id)
                        })
                        let loadding = this.openLoading();
                        this.$http.post('Finance/DeleteFinanceReimbursement', arrDel).then(res => {
                            loadding.close();
                            if (res.data.IsSuccess) {
                                this.$message.success('删除成功!')
                                this.SelectMore_lis = []
                                this.GetFinanceReimbursementDetail()
                            } else {
                                this.$message.error(res.data.Msg)
                            }
                        }).catch(() => {
                            loadding.close();
                            this.$message.info('服务器异常,请联系管理员!')
                        })
                    } else {
                        this.$message.warning('没有选中的数据!')
                    }
                }).catch(() => {
                    this.$message.info('已取消!')

                })
            },

            //获取数据表格
            GetFinanceReimbursementDetail() {
                let Loading = this.openLoading();
                this.$http.post('/Finance/GetFinanceReimbursementDetail',
                    {
                        form: this.form,
                        date: this.date,
                        finance: this.finance,
                        currentPage: this.pagination.currentPage,
                        pagesize: this.pagination.pagesize,
                    }
                ).then(res => {
                    Loading.close();
                    this.tableData = res.data.data;
                    this.pagination.total = res.data.count;
                });
            },
            //重置查询
            GetFinanceReimbursementDetail_Refresh(){
                this.$refs["queryform_FinanceReimbursement"].resetFields()
                this.form.Start = ''
                this.form.End = ''
                this.GetFinanceReimbursementDetail()
            },

            _UserById(id) {
                return publicjs.GetDataUserNameById(this.AllUsers, id);
            },

            _GetAllDepartmentById(id) {
                return publicjs.GetDepartmentNameById(id)
            },
            _GetProjectById(id) {
                return publicjs.GetProjectNameById(id)
            },
            _GetPayeerName(obj) {
                return publicjs.GetpayeerNameById(obj.PayeeType, obj.Payee)
            },

            _GetInitStateColum(obj) {
                return publicjs.InitStateColum(obj);
            },
            doNewDateTotime(time){
                if(time){
                    return publicjs.formatDate(new Date(time),"yyyy-MM-dd hh:mm:ss")
                }else{
                    return "";
                }
            },
            //用于构造人员多选的字符串
            _MultipleString(data) {
                var result = "";
                if (data != null && data.length > 0) {
                    var arr = data.split(',');
                    for (var i = 0; i < this.AllUsers.length; i++) {
                        for (var z = 0; z < arr.length; z++) {

                            if (this.AllUsers[i].Id == arr[z]) {
                                if (result.length == 0) {
                                    result += this.AllUsers[i].UserName;
                                }
                                else {
                                    result = result + "," + this.AllUsers[i].UserName;
                                }
                            }
                        }
                    }
                }
                return result;
            },

            //添加报销信息
            ShowAddFinanceReimbursement() {
                this.$http.get("/Finance/AddFinanceReimbursementBit").then(res => {
                    if (res.data.mes.IsSuccess) {
                        this.AddFinanceReimbursementShow = true;
                    } else {
                        this.$message.error(res.data.mes.Msg);
                    }
                });
            },
            //修改项目
            edit(obj) {
               this.FinanceLoanDB = obj
                        this.GetTable(obj);
                        this.UpFinanceReimbursementShow = true;
            },

            GetTable(obj) {
                this.$http.get("/Finance/UpdateFinanceReimbursementBit?id=" + obj.Id).then(res => {
                    this.detailed = JSON.parse(JSON.stringify(res.data.FinanceDocDetails));
                    this.FinanceLoanDB = res.data;
                });
            },

            order(obj) {
                // ParentOpen('报销单----' + obj.data.ReimNumber, '/Report/FinanceReimbursementOrder?ReimNumber=' + obj.data.ReimNumber, callBack = false);
                this.$http.get("/Finance/FinanceReimbursementOrderBit?ReimNumber=" + obj.ReimNumber).then(res => {
                    if (res.data.IsSuccess) {
                        this.FinanceLoanDB = obj;
                        this.FinanceReimbursementOrderShow = true;
                    } else {
                        this.$message.error(res.data.Msg);
                    }
                });
            },

            layEvent(obj) {
                this.$http.get("/Finance/ViewFinanceAndRecordBit?LoanNumber=" + obj.LoanNumber).then(res => {
                    if (res.data.mes.IsSuccess) {
                        this.ViewFinanceAndRecordShow = true;
                        this.ViewFinanceAndRecorDB = res.data.obj
                    } else {
                        this.$message.error(res.data.mes.Msg)
                    }
                });
            },
        },
    }
</script>


<style scoped>

    .big_box {
        padding: 15px;
    }

    .row-bg {
        padding: 10px 0;
        background-color: #f9fafc;
    }

    .buttongroup {
        margin-right: 5px !important;
        border-radius: 4px !important;
    }

    .DialogTable {
        position: fixed;
    }

    .col {
        margin-left: 10px;
    }
    .elformitem{
        margin-bottom: 0px !important;
    }
</style>
